package com.qxglxt.qxglxt.dao;

import java.util.List;

import javax.transaction.Transactional;

import com.qxglxt.qxglxt.model.Users;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface IUsersDao extends JpaRepository<Users,String>,JpaSpecificationExecutor<Users>{
    @Transactional
    @Modifying
    @Query("update Users u set u.PassWord='ysd123' where u.id=:id")
    int pwdReset(String id);
    @Transactional
    @Modifying
    @Query("update Users u set u.IsLockout='是' where u.id=:id")
    int lockoutUser(String id);
    @Transactional
    @Modifying
    @Query("update Users u set u.IsLockout='否' where u.id=:id")
    int notLockoutUser(String id);
    @Query("delete from Users u where u.id=:id")
   void deleteById(String id);//查询指定用户的角色
    @Transactional
    @Modifying
    @Query(value = "delete from role_user where user_id=:userId and role_id in (:rolesId)",nativeQuery = true)
    int betachUserRoles(String userId,List<String> rolesId);

    @Query(value = "select * from Users u where u.login_name=?1 and u.pass_word=?2",nativeQuery = true)
    Users login(String loginName,String passWord);

}